<template>
  <section>
    <!--工具条-->
    <toolbar :buttonList="buttonList" @callFunction="callFunction"></toolbar>
    <el-form
      :inline="true"
      :model="params"
      class="demo-form-inline"
      style="margin-left: 20px"
    >
    <el-form :inline="true" :model="params" class="demo-form-inline" style="margin-left:20px;">
      <el-button @click="handleAdd()">新增</el-button>
      <el-button @click="handleEdit()">编辑</el-button>
      <el-button @click="handleDel()">删除</el-button>
      <el-form-item label="商品状态" style="margin-left: 30px">
        <el-form-item label="商品状态" style="margin-left:30px;">
        <el-select v-model="params.key" placeholder="活动区域">
          <el-option label="上架" value="shanghai"></el-option>
          <el-option label="下架" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品分类">
        <el-select v-model="params.key" placeholder="活动区域">
          <el-option label="医疗器械" value="yiliao"></el-option>
          <el-option label="健康保险" value="baoxian"></el-option>
          <el-option label="婴幼用户" value="yingyou"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-input
          v-model="params.key"
          placeholder="请输入要分类的商品"
        ></el-input>
            <el-input v-model="params.key" placeholder="请输入要分类的商品"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      :data="drugs"
      v-loading="listLoading"
      @select="dialogCheck"
      @row-click="selectCurrentRow"
      ref="table"
      class="custom-tbl"
      style="width: 100%"
    >
      <el-table-column type="selection" width="50">
      </el-table-column>
      <el-table-column type="index"  label="序号" width="80">
      </el-table-column>
      <el-table-column prop="DrugName" label="药品名称" width="200" >
      </el-table-column>
      <el-table-column prop="DrugFacts" label="药品说明" width="200" >
      </el-table-column>
      <el-table-column prop="DrugSkuId" label="药品外键" width="200" >
      </el-table-column>
      <el-table-column prop="Createdby" label="创建人" width="200" >
      </el-table-column>
      <el-table-column prop="Updatedby" label="更新人" width="200" >
      </el-table-column>
      <el-table-column label="操作" width="200" style="margin-right:20px;">
                <template scope="scope">
                    <el-link size="primary" @click="handleShang(scope.$index, scope.row)">上架</el-link>&nbsp;
                    <el-link size="primary" @click="handleXia(scope.$index, scope.row)">下架</el-link>&nbsp;
                    <el-link size="primary" @click="handleXiang(scope.$index, scope.row)">详情</el-link>&nbsp;
                    <el-link size="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-link>&nbsp;
                </template>
            </el-table-column>
    </el-table>
    <!-- 工具条 -->
    <el-col :span="24" class="toolbar">
      <!-- 分页 -->
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="this.params.pageIndex"
          :page-sizes="[2, 3, 4, 5]"
          :page-size="this.params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
      :total="this.pageCount">
          :total="this.pageCount"
        >
        </el-pagination>
      </div>
    </el-col>



    <!--新增界面-->
    <el-dialog
      title="新增"
      :visible.sync="addFormVisible"
      v-model="addFormVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="addForm"
        label-width="80px"
        :rules="addFormRules"
        ref="addForm"
      >
        <el-form-item label="昵称" prop="uRealName">
          <el-input v-model="addForm.uRealName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="登录名" prop="uLoginName">
          <el-input v-model="addForm.uLoginName" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="uLoginPWD">
          <el-input
            v-model="addForm.uLoginPWD"
            show-password
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="所属部门"
          v-if="options && options.length > 0"
          prop="Dids"
        >
          <el-cascader
            placeholder="请选择，支持搜索功能"
            style="width: 100%"
            v-model="addForm.Dids"
            :options="options"
            filterable
            :key="isResouceShow"
            :props="{ checkStrictly: true, expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="性别">
          <el-radio-group v-model="addForm.sex">
            <el-radio class="radio" :label="1">男</el-radio>
            <el-radio class="radio" :label="0">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄">
          <el-input-number
            v-model="addForm.age"
            :min="0"
            :max="200"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="生日">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="addForm.birth"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="地址">
          <el-input type="textarea" v-model="addForm.addr"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="addFormVisible = false">取消</el-button>
        <el-button
          type="primary"
          @click.native="addSubmit"
          :loading="addLoading"
          >提交</el-button
        >
      </div>
    </el-dialog>
  </section>
</template>


<script>

import {
  testapi,
  getDrugsListPage,
  getDrugsList,
} from "../../api/api";//当前这个模块所调用的方法

import { getButtonList } from "../../promissionRouter";//获取权限按钮
import Toolbar from "../../components/Toolbar";


export default {
  components: { Toolbar },
  //定义数据模型
    data(){
      return{
        drugs:[],
      roles: [],
      options: [],
      listLoading: false,
        buttonList:[],
        params:{//查询参数
        //page pageSize pageIndex
          pageIndex: 1,//当前页面
          pageSize: 10,//页面大小
          key:''//查询表的数据
      },
      filters: {
        name: "",
      },
        pageCount:0,
      sels: [], //列表选中列
      //新增界面数据
      addForm: {
        name: "",
        uLoginName: "",
        uRealName: "",
        uLoginPWD: "",
        sex: -1,
        age: 0,
        birth: "",
        Dids: [],
        DepartmentId: 0,
        addr: "",
      },
      isResouceShow: 0,
      addFormVisible: false, //新增界面是否显示
      addLoading: false,
      addFormRules: {
        uLoginName: [
          { required: true, message: "请输入登录名", trigger: "blur" },
        ],
        uRealName: [{ required: true, message: "请输入昵称", trigger: "blur" }],
        uLoginPWD: [{ required: true, message: "请输入密码", trigger: "blur" }],
        birth: [{ required: true, message: "请填写生日", trigger: "blur" }],
      },
      }
  },
  //定义方法
    methods:{
      handleShang(row,index){
        console.log(row,index);
    },
      handleXia(row,index){
        console.log(row,index);
    },
      handleXiang(row,index){
        console.log(row,index);
    },
      handleEdit(row,index){
        console.lig(row,index);
    },
    handleCurrentChange(val) {
      this.pageIndex = val;
      this.getList();
    },
    handleSizeChange(val) {
          this.pageSize=val;
      this.getList();
    },
      getList(){

      let params = {
        page: this.pageIndex,
        key: this.filters.name,
      };
      this.listLoading = false;

      testapi();
      //调用接口获取数据
          getDrugsListPage(this.params).then(res => {
        console.log("药品列表：", res.data);
        this.drugs = res.data.response.data;
        this.pageCount = res.data.response.pageCount;
          })
    },
    //显示新增界面
    handleAdd() {
      this.addFormVisible = true;
      this.options = [];
      this.addForm = {
        uLoginName: "",
        uRealName: "",
        uLoginPWD: "",
        name: "",
        sex: -1,
        age: 0,
        Dids: [],
        DepartmentId: 0,
        birth: "",
        addr: "",
      };
    },
    //查询
      onSubmit(){
        console.log('submit!');
      this.getList();
    },
    dialogCheck(selection, row) {
      this.currentRow = null;
      this.$refs.table.clearSelection();
      if (selection.length === 0) {
        return;
      }
      if (row) {
        this.selectCurrentRow(row);
      }
    },
    callFunction(item) {
      this.filters = {
        name: item.search,
      };
      this[item.Func].apply(this, item);
    },
      selectCurrentRow(val){
      if (val) {
        this.currentRow = val;
        this.$refs.table.clearSelection();
        this.$refs.table.toggleRowSelection(val, true);
      }
    },
  },
  //定义事件处理八大生命周期函数之一 挂载后事件
    mounted(){
      this.getList();//调用接口，获取列表数据
    //获取权限按钮
    let routers = window.localStorage.router
      ? JSON.parse(window.localStorage.router)
      : [];
    this.buttonList = getButtonList(this.$route.path, routers);
  },
  //创建事件
    create(){
      
    },
  }
</script>

<style scoped>
.custom-tbl /deep/ .has-gutter .el-checkbox {
  display: none;
}
</style>
